package com.cloudlinkscm.loms.services.base.notify.assemblers;

import com.cloudlinkscm.loms.framework.core.pojo.Assembler;
import com.cloudlinkscm.loms.framework.util.BeanUtils;
import com.cloudlinkscm.loms.services.base.notify.constant.SendStatusEnum;
import com.cloudlinkscm.loms.services.base.notify.dto.email.EmailMessageDto;
import com.cloudlinkscm.loms.services.base.notify.model.entity.EmailMessage;
import org.springframework.stereotype.Component;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;

/**
 * @author : tac
 * @date : 2017/6/15
 */

@Component
public class EmailMessageModelAssembler implements Assembler<EmailMessageDto, EmailMessage> {
    @Override
    public EmailMessageDto toDto(EmailMessage bo) {
        throw new NotImplementedException();
    }

    @Override
    public EmailMessage toBo(EmailMessageDto dto) {
        EmailMessage mail = new EmailMessage();
        BeanUtils.copyProperties(dto, mail);
        mail.setStatus(SendStatusEnum.NOT_SEND.val);
        mail.setReply(isNotNull(dto.getReplyUrl()));
        mail.setUrl(isNotNull(dto.getUrlHead()));
        mail.setResendNum(0);
        return mail;
    }

    private boolean isNotNull(Object field) {
        return field != null;
    }
}
